// This is mutant program.
// Author : ysma

package example;


public class ItemList
{

    example.Item first;

    static example.Item last;

    public ItemList()
    {
    }

    public ItemList( example.Item item )
    {
        first = item;
        last = item;
    }

    public example.Item first()
    {
        return first;
    }

    public example.Item last()
    {
        return last;
    }

    public void add( example.Item item )
    {
        if (first == null) {
            first = item;
            last = first;
            return;
        }
        last.next = item;
        last = item;
    }

    public void remove( example.Item item )
    {
        if (first == null) {
            return;
        }
        if (item == null) {
            return;
        }
        if (item == last) {
            example.Item p = first;
            while (p.next != last) {
                p = p.next;
            }
            p.next = null;
            last = p;
            return;
        }
        item = item.next;
    }

    public void purge()
    {
        example.Item p;
        example.Item q;
        p = first;
        while (p != null) {
            q = p.getNext();
            while (q != null) {
                if (p.getName().compareTo( q.getName() ) == 0) {
                    this.remove( q );
                }
                q = q.getNext();
            }
            p = p.getNext();
        }
    }

}
